<template>
	<view>
		<cu-custom :bgcolor="'#fff'" />
		<view v-if="shopList && shopList.length >0">
			<scroll-view scroll-y="true" :style="'height:'+scorllHeight+ 'px;'">
				<view class="shop-list">
					<view class="list-box pt-3 pb-3 pl-4 pr-4 mb-2" v-for="(item, index) in shopList" :key="index">
						<view class="list pb-2">
							<view class="list-center-info span-20 d-flex flex-column a-center j-sb">
								<view class="d-flex flex-row  span-20" style="color: #999999;">
									<image v-if="item.img_original" :src="item.img_original"
										style="width: 100%; height: 220rpx; margin-bottom: 20rpx;" mode=""></image>
									<view class="no-img" v-else></view>
								</view>
								<view class="d-flex flex-row  span-20" style="color: #999999;">
									<uni-forms ref="baseForm" :modelValue="formData" label-width="30">
										<uni-forms-item label="排序">
											<uni-easyinput v-model="item.img_sort" placeholder="请输入排序" />
										</uni-forms-item>
									</uni-forms>

								</view>

							</view>
						</view>
						<view class="list-btn mt-3 d-flex flex-row a-center j-end">
							<button class="mini-btn m-0 mr-2 input-border-color border bg-none main-text-color" type="default" size="mini"
								@click.stop="toDetail(item.img_id)">更换图片</button>
							<button class="mini-btn m-0 main-bg-color text-white" type="default" size="mini"
								@click.stop="sureBanner(item)">更改排序</button>
						</view>
					</view>

				</view>
				<!-- <view class="d-flex a-center j-center text-light-muted font-md py-3">{{loadtext}}</view> -->
			</scroll-view>

		</view>
		<view v-else class="text-center mt-5">
			暂无数据
		</view>
		<!-- <view class="button-box p-2">
			<button class="main-bg-color text-white font-md" @click="toAddShop">新增店铺广告</button>
		</view> -->
	</view>
</template>

<script>
	import title from "@/components/common/title.vue"
	import divider from "@/components/common/divider.vue"
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			title,
			divider,
			cuCustom
		},
		data() {
			return {
				scorllHeight: 500,
				shopList: [],
				loadtext: "上拉加载更多",
				allChecked: false,
				formData: {
					name: ""
				},
				getApp:""
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res => {
					this.scorllHeight = res.windowHeight - uni.upx2px(200)
				})
			})
			this.getApp = getApp()
		},
		onShow() {
			this.getShopClassList()
		},
		methods: {
			
			toDetail(id) {
				uni.navigateTo({
					url: './addAdvertisement?id=' + id
				})
			},
			sureBanner(item){
				let _that = this
				if(item.img_original){
					interceptor.get('/supplier_applet_api.php?act=confirmBannerSort', {
						id: item.img_id,
						sort: item.img_sort
					}).then((res) => {
						if (res.status === 1) {
							uni.showToast({
								title: res.msg,
								icon:"none"
							})
							_that.getShopClassList()
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
				}else{
					uni.showToast({
						title:"请设置图片，在调整排序",
						icon:"none"
					})
				}
			},
			getShopClassList() {
				this.shopList = []
				interceptor.get('/supplier_applet_api.php?act=toBannerList', {
					supplier_id: uni.getStorageSync("supplier_id")
				}).then((res) => {
					if (res.status === 1) {
						const {
							info
						} = res
						this.shopList = info.supplierRotationPicture
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		width: 100%;
		height: 160upx;
		background: #fff;

		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.input {
			width: 100%;
			border-radius: 20px;
			overflow: hidden;
			border: 1px solid #BBBBBB;
			position: relative;

			.icon-sousuo {
				position: absolute;
				left: 35upx;
				top: 10upx;
			}

			.search {
				position: absolute;
				right: 40upx;
				top: 8upx;
			}
		}
	}

	.shop-list {
		background: #EBECED;
		height: auto;
		padding: 32rpx;
		box-sizing: border-box;

		.list-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			height: auto;

			.list {
				height: auto;
				border-bottom: 1px dashed #dcdcdc;
			}

			.list-btn {}
		}

	}

	.button-box {
		position: absolute;
		width: 100%;
		bottom: 0;
		background: #fff;
		height: 100rpx;
		box-sizing: border-box;
		height: 140rpx;
	}
	.no-img{
		width: 100%;
		height: 220rpx;
		margin-bottom: 20rpx;
		background: #EBECED;
		border-radius: 8rpx;
	}
</style>